package com.ruoyi.business.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.JtProductInventoryDetails;
import com.ruoyi.business.service.IJtProductInventoryDetailsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品库存明细Controller
 * 
 * @author Alan Zhang
 * @date 2025-06-13
 */
@Controller
@RequestMapping("/business/inventory/details")
public class JtProductInventoryDetailsController extends BaseController
{
    private String prefix = "business/inventory/details";

    @Autowired
    private IJtProductInventoryDetailsService jtProductInventoryDetailsService;

    @RequiresPermissions("inventory:details:view")
    @GetMapping()
    public String details()
    {
        return prefix + "/details";
    }

    /**
     * 查询商品库存明细列表
     */
    @RequiresPermissions("inventory:details:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JtProductInventoryDetails jtProductInventoryDetails)
    {
        startPage();
        List<JtProductInventoryDetails> list = jtProductInventoryDetailsService.selectJtProductInventoryDetailsList(jtProductInventoryDetails);
        return getDataTable(list);
    }

    /**
     * 导出商品库存明细列表
     */
    @RequiresPermissions("inventory:details:export")
    @Log(title = "商品库存明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JtProductInventoryDetails jtProductInventoryDetails)
    {
        List<JtProductInventoryDetails> list = jtProductInventoryDetailsService.selectJtProductInventoryDetailsList(jtProductInventoryDetails);
        ExcelUtil<JtProductInventoryDetails> util = new ExcelUtil<JtProductInventoryDetails>(JtProductInventoryDetails.class);
        return util.exportExcel(list, "商品库存明细数据");
    }

    /**
     * 新增商品库存明细
     */
    @RequiresPermissions("inventory:details:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商品库存明细
     */
    @RequiresPermissions("inventory:details:add")
    @Log(title = "商品库存明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JtProductInventoryDetails jtProductInventoryDetails)
    {
        return toAjax(jtProductInventoryDetailsService.insertJtProductInventoryDetails(jtProductInventoryDetails));
    }

    /**
     * 修改商品库存明细
     */
    @RequiresPermissions("inventory:details:edit")
    @GetMapping("/edit/{detailsId}")
    public String edit(@PathVariable("detailsId") Long detailsId, ModelMap mmap)
    {
        JtProductInventoryDetails jtProductInventoryDetails = jtProductInventoryDetailsService.selectJtProductInventoryDetailsByDetailsId(detailsId);
        mmap.put("jtProductInventoryDetails", jtProductInventoryDetails);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品库存明细
     */
    @RequiresPermissions("inventory:details:edit")
    @Log(title = "商品库存明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JtProductInventoryDetails jtProductInventoryDetails)
    {
        return toAjax(jtProductInventoryDetailsService.updateJtProductInventoryDetails(jtProductInventoryDetails));
    }

    /**
     * 删除商品库存明细
     */
    @RequiresPermissions("inventory:details:remove")
    @Log(title = "商品库存明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jtProductInventoryDetailsService.deleteJtProductInventoryDetailsByDetailsIds(ids));
    }
}
